package self.niu.com.resume.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;

import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;

import self.niu.com.resume.R;
import self.niu.com.resume.ui.ProgressUtils;

public class WebVeiwActivity extends AppCompatActivity {
    @ViewInject(R.id.web_back_tv)
    private TextView back;
    @ViewInject(R.id.web_scan_web)
    private WebView web;
    @ViewInject(R.id.empty)
    private TextView empty;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_web_veiw);
        ViewUtils.inject(this);
        String url = getIntent().getStringExtra("url");
        if (url.equals("")) {
            empty.setVisibility(View.VISIBLE);
        } else {
            ProgressUtils.getInstances().showProgress(this);
            initView(url);
        }
    }

    private void initView(String url) {

        web.getSettings().setJavaScriptEnabled(true);
        web.loadUrl(url);
        HelloWebViewClient hwc = new HelloWebViewClient();
        web.setWebViewClient(hwc);
        web.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                super.onProgressChanged(view, newProgress);
                if (newProgress == 100) {
                    ProgressUtils.getInstances().hideProgress();
                }
            }
        });
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }


    //Web视图
    private class HelloWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    }
}